//
//  NewCityGoodsListCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/9/14.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

class NewCityGoodsListCell: BaseTableViewCell {
    
    @IBOutlet weak var leftImageView: UIImageView!
    
    @IBOutlet weak var nameLabel: UILabel!
    
    @IBOutlet weak var prieLabel: UILabel!
    
    @IBOutlet weak var evaluationLabel: UILabel!

    @IBOutlet weak var favourableLabel: UILabel!

    @IBOutlet weak var middlLineLabel: UILabel!
    
    @IBOutlet weak var indetorView: UIActivityIndicatorView!
    
    var model : HomeItemModel?{
        
        didSet{
            
            if model == nil {
                return
            }
            
            indetorView.startAnimating()
            
            leftImageView.sd_setImage(with: URL(string: model!.goods_image_url), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                self.indetorView.stopAnimating()
                
            }
            
            nameLabel.text = model?.goods_name
            
            prieLabel.text = "¥ \(model!.goods_price)"
            
            evaluationLabel.text = "99%好评"
            
            var temp : Float = Float(model!.goods_price) ?? 0
            
            temp = temp * 0.2 + temp
            
            middlLineLabel.attributedText = attributedString2(str: "零售价:\(temp)", font: UIFont.systemFont(ofSize: 13))
            
        }
        
    }


    override func awakeFromNib() {
        super.awakeFromNib()
        contentView.backgroundColor = UIColor.white
        evaluationLabel.textColor = UIColor.dakGray()
        favourableLabel.backgroundColor = UIColor.viewBgGrey()
        favourableLabel.addCornerAndBorder(borderColor: nil, borderWidth: 0, masksToBounds: true, cornerRadius: 3)
        favourableLabel.textColor = UIColor.red
        // Initialization code
    }
    
    
    
    
    func attributedString2(str: String, font: UIFont) -> NSAttributedString? {
        
        
        // 根据原有字符串生成属性字符串
        let strM = NSMutableAttributedString(string: str)
        
        strM.addAttribute(NSFontAttributeName, value: font, range:NSMakeRange(0, str.characters.count))
        
        strM.addAttribute(NSForegroundColorAttributeName, value: UIColor.dakGray(), range:NSMakeRange(0, str.characters.count) )
        
        strM.addAttribute(NSBaselineOffsetAttributeName, value: 1, range:NSMakeRange(0, str.characters.count) )

        
        strM.addAttribute(NSStrikethroughStyleAttributeName, value:  NSUnderlineStyle.styleSingle.rawValue, range:NSMakeRange(0, str.characters.count) )
        
        
//        let paragr = NSMutableParagraphStyle.init()
//        
//        paragr.firstLineHeadIndent = 6;
//        
//        paragr.lineSpacing = 2;
//        
//        strM.addAttribute(NSParagraphStyleAttributeName, value: paragr, range: NSMakeRange(0, str.characters.count))
//        
        
        
        return strM
        
        
        
        
        
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
